#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from product import *
from admin import *
import cgi

form = cgi.FieldStorage()
msg=""

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value

if form.has_key(u"product_id"): 
   product_id = form[u"product_id"].value  
else:
   msg+=u"<br/><b>*** Error : Champ product_id vide ! ***</b>"

# GET ADMIN CONTENT
adm=AdminCms()
print adm.getPageHeader()
print adm.getAdminMenu()

## GET CONTENT PRODUCT
if product_id:
  p=Product()
  product=p.read(product_id)
  if product == 0:
    msg+=u"<br/>Erreur Produit (ID:%s) inacessible !" % product_id
    print u"<tr><td colspan='3'><div id='active_page'>%s</div></td></tr>" % msg
  else:
    print "<tr><td colspan='3'><div id='active_page'><br/><h3>Modification du Produit %s (ID:%s)&nbsp;&nbsp;<a href='#' onclick='newProduct()' ><img src='/img/add_icon.gif' title='Nouveau Produit' width='16' height='16' ></a></h3><br/><div id='msg_box'>&nbsp;</div><table border='0' cellpadding='0' cellspacing='0' align='center'><tr><td class='adminTitle'>R&eacute;f&eacute;rence :</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='20' id='reference' value='%s'></td></tr><tr><td class='adminTitle'>D&eacute;signation :</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='100' id='designation' value='%s'></td></tr><tr><td class='adminTitle'>Description :</td></tr><tr><td class='adminField'><textarea rows='8' cols='24' id='description'>%s</textarea></td></tr><tr><td class='adminTitle'>Options :</td></tr><tr><td class='adminField'><textarea rows='6' cols='24' id='option'>%s</textarea></td></tr><tr><td class='adminTitle'>Image (nom.jpg) :</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='150' id='image' value='%s'></td></tr><tr><td class='adminTitle'>Prix (HT):</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='13' id='price' value='%s'></td></tr><tr><td class='adminTitle'>Taxe :</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='13' id='tax' value='%s'></td></tr><tr><td class='adminTitle'>Disponible :</td></tr><tr><td class='adminField'><select id='dispo'><option value='oui' selected >Oui</option><option value='non'>Non</option></select></td></tr><tr><td class='adminTitle'>Quantit&eacute; en stock :</td></tr><tr><td class='adminField'><input type='text' size='24' maxlength='13' id='stock' value='%s'></td></tr></table><input type='hidden' id='product_id' value='%s'><input type='button' onclick='updateProduct()' value='Enregistrer' title='Sauvegarder les modifications'></div></td></tr>" % ( product[u'prod_desig'], product_id, product[u'prod_ref'], product[u'prod_desig'], product[u'prod_desc'], product[u'prod_option'], product[u'prod_img'], product[u'prod_price'], product[u'prod_tax'], product[u'prod_stock'], product_id )

else:
   print u"<tr><td colspan='3'><div id='active_page'>%s</div></td></tr>" % msg

print adm.getPagesList()
print adm.getPageFooter()
